<?php
$T->loadTpl("./html/".$template."/".$qname.".html");
$T->SetTpl('cssjs','html/cssjs.inc'); 
$T->SetTpl('jsmodel','html/jsmodel.inc');     
  
$id=isset($_GET["eid"])?$_GET["eid"]:"0";
$emailbox=isset($_GET["emailbox"])?$_GET["emailbox"]:"";
$read_flag=isset($_GET["read_flag"])?$_GET["read_flag"]:"1";
if($id!="0"){
    $email=$T->db->query("select A.*,B.truename from sys_email A left join sys_member B on A.sender=B.id where A.id={$id}")->fetch(PDO::FETCH_ASSOC);
    
    $receiver=$email['receiver'];
	$receiver=explode(",", $receiver);
	foreach($receiver as $k=>$v){
		$receiver[$k]="'".$v."'";
	}
	$receiver=implode(",", $receiver);
    $receiver_info=$T->db->query("select truename from sys_member where id in({$receiver})")->fetchAll(PDO::FETCH_COLUMN);
    $email['receiver']=implode(",", $receiver_info);
	$email['receiver_limit']=mb_get_str(0,50,$email['receiver']);
    foreach($email as $k=>$v){
    	if($k=='timestamp'&&$v!=''){
    		$T->Set($k,date("Y-m-d H:i:s",$v));
    	}elseif($k=='content'&&$v!=''){
    	    $T->Set($k,htmlspecialchars_decode($v,ENT_QUOTES));
    	}else{
    		$T->Set($k,$v);
    	}
    }
	$attachment=$email['attachment'];
	//if($attachment!=''){
		$attachment=explode(",", $attachment);
		foreach($attachment as $k=>$v){
			$attachment[$k]="'".$v."'";
		}
		$attachment=implode(",", $attachment);
		$T->SetBlock("attachment", "select * from sys_email_attachment where id in({$attachment}) order by `timestamp`");
	//}
	
}
$T->Set('emailbox',$emailbox);
$T->Set('read_flag',$read_flag);

$T->Set("template",$template);         
$T->clearNaN();       
$T->clearNoN();
$T->display(); 